﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Utilities;
using CrystalDecisions.CrystalReports.Engine;

namespace ManageTicket.Report
{
    public partial class frmChooseDate : Form
    {
        #region Contructor
        public frmChooseDate(string type)
        {
            InitializeComponent();
            TYPE = type;
        }
        #endregion

        #region Variable
        clsMethod4All objMethod = new clsMethod4All();
        private string TYPE = "";
        #endregion

        #region Event
        private void frmChooseDate_Load(object sender, EventArgs e)
        {
            switch (TYPE)
            {
                case "PROFIT":
                    this.Text = "Báo cáo doanh thu";
                    break;
                case "FINANCE":
                    this.Text = "Báo cáo tài chính";
                    break;
            }
            //default date value
            dtpDateFrom.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1, 0, 0, 0);
            dtpDateTo.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, objMethod.GetEndDayOfMonth(DateTime.Now.Month, DateTime.Now.Year), 23, 59, 59);
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            switch (TYPE)
            {
                case "PROFIT":
                    ReportProfit();
                    break;
                case "FINANCE":
                    ReportFinance();
                    break;
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion

        #region Method
        private void ReportProfit()
        {
            DataTable dtProfit = objMethod.CreateDataTable("PROFIT", new string[] {"VOUCHER", "DATE_OF_VOUCHER", "EMPLOYEE", 
                "VND_BUY", "VND_SALE", "VND_PROFIT", "USD_BUY", "USD_SALE", "USD_PROFIT",
                "REAL_VND_BUY", "REAL_VND_SALE", "REAL_VND_PROFIT", "REAL_USD_BUY", "REAL_USD_SALE", "REAL_USD_PROFIT"});





            //DataRow row;
            //foreach (DataObjects.Voucher oVou in arr)
            //{
            //    row = dtFinance.NewRow();
            //    row["NGANHANG"] = "";
            //    row["TAIKHOAN"] = "";
            //    row["VON"] = "";
            //    row["NGAYTHU"] = "";
            //    row["SOTIENTHU"] = "";
            //    row["NOIDUNGTHU"] = "";
            //    row["VETHU"] = "";
            //    row["HCTHU"] = "";
            //    row["NGAYCHI"] = "";
            //    row["SOTIENCHI"] = "";
            //    row["NOIDUNGCHI"] = "";
            //    row["VECHI"] = "";
            //    row["HCCHI"] = "";
            //    dtFinance.Rows.Add(row);
            //}

            Report.rptProfit objProfit = new ManageTicket.Report.rptProfit();
            objProfit.SetDataSource(dtProfit);
            FormulaFieldDefinitions crFormulas;
            crFormulas = objProfit.DataDefinition.FormulaFields;
            crFormulas["DateFrom"].Text = "'" + dtpDateFrom.Value.ToString("dd/MM/yyyy").Replace("'", "''") + "'";
            crFormulas["DateTo"].Text = "'" + dtpDateTo.Value.ToString("dd/MM/yyyy").Replace("'", "''") + "'";

            Report.frmReport objReport = new ManageTicket.Report.frmReport(objProfit);
            objReport.ShowDialog();
        }

        private void ReportFinance()
        {
            DataTable dtFinance = objMethod.CreateDataTable("FINANCE", new string[] {"NGANHANG", "TAIKHOAN", "VON", 
                "NGAYTHU", "SOTIENTHU", "NOIDUNGTHU", "VETHU", "HCTHU", 
                "NGAYCHI", "SOTIENCHI", "NOIDUNGCHI", "VECHI", "HCCHI"});

            

           

            //DataRow row;
            //foreach (DataObjects.Voucher oVou in arr)
            //{
            //    row = dtFinance.NewRow();
            //    row["NGANHANG"] = "";
            //    row["TAIKHOAN"] = "";
            //    row["VON"] = "";
            //    row["NGAYTHU"] = "";
            //    row["SOTIENTHU"] = "";
            //    row["NOIDUNGTHU"] = "";
            //    row["VETHU"] = "";
            //    row["HCTHU"] = "";
            //    row["NGAYCHI"] = "";
            //    row["SOTIENCHI"] = "";
            //    row["NOIDUNGCHI"] = "";
            //    row["VECHI"] = "";
            //    row["HCCHI"] = "";
            //    dtFinance.Rows.Add(row);
            //}

            Report.rptFinance objFinance = new ManageTicket.Report.rptFinance();
            objFinance.SetDataSource(dtFinance);
            FormulaFieldDefinitions crFormulas;
            crFormulas = objFinance.DataDefinition.FormulaFields;
            crFormulas["DateFrom"].Text = "'" + dtpDateFrom.Value.ToString("dd/MM/yyyy").Replace("'", "''") + "'";
            crFormulas["DateTo"].Text = "'" + dtpDateTo.Value.ToString("dd/MM/yyyy").Replace("'", "''") + "'";

            Report.frmReport objReport = new ManageTicket.Report.frmReport(objFinance);
            objReport.ShowDialog();
        }
        #endregion
 
    }
}
